package com.matrix.thread;

public class TheadTest extends Thread{

    private String str;
    private String ThreadName;


    public String getThreadName() {
        return ThreadName;
    }

    public void setThreadName(String threadName) {
        ThreadName = threadName;
    }

    public TheadTest(String str) {
        this.str = str;
    }

    @Override
    public void run() {
        this.setName(str);
        ThreadName = Thread.currentThread().getName();
        System.out.println("线程正在运行："+str);
    }

    public static void main(String[] args) throws InterruptedException {
        String ThreadName;
        TheadTest thread1 = new TheadTest("线程1");
        TheadTest thread2 = new TheadTest("线程2");
        thread1.run();
        thread2.start();
        Thread.sleep(1000);
        System.out.println("线程1所在的线程："+thread1.getThreadName());
        System.out.println("线程2所在的线程："+thread2.getThreadName());
    }
}
